package service.impl;

import dao.StudentDao;
import dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Student;
import pojo.User;
import service.StudentService;

import java.util.Date;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Autowired
    private UserDao userDao;


    @Override
    public List<Student> findAll(Student stu, int offset, int pageSize) {

        // 以下两种方式均可
//        List<User> users = userDao.findAll(user.getName(),user.getPass(),offset,pageSize);
        stu.setDelFlag("0");
        List<Student> students = studentDao.findAll2(stu,offset,pageSize);
        return students;
    }


    @Override
    public int count(Student stu) {
        return studentDao.count(stu);
    }

    @Override
    public int deleteStudentById(int sId) {
        return studentDao.deleteStudentById(sId);
    }

    @Override
    public int addStudent(Student stu) {
        stu.setCreateTime(new Date());
        stu.setDelFlag("0");
        return studentDao.addStudent(stu);
    }

    @Override
    public Student findStudentById(int sId) {
        return studentDao.findStudentById(sId);
    }

    @Override
    public int updateStudent(Student stu) {
        stu.setUpdateTime(new Date());
        return studentDao.updateStudent(stu);
    }

    @Override
    public boolean login(User user) {
        if(userDao.login(user) > 0){
            return true;
        }
        return false;
    }
}
